#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const long long INF=1e16;
const int maxn=100010;
long long dp[maxn],M;
int n,a[maxn],f[maxn],l[maxn],r[maxn];
long long min(long long x,long long y){return x<y?x:y;}
long long max(long long x,long long y){return x>y?x:y;}
int main()
{
	while(scanf("%d%lld",&n,&M)!=EOF)
	{
		for(int i=1;i<=n;i++)
			scanf("%d",&a[i]);
		for(int i=1;i<=n;i++){dp[i]=INF;l[i]=r[i]=1;}
		if(a[1]<=M)dp[1]=a[1];
		for(int i=2;i<=n;i++)
		{
			long long sum=0,tem=-1;
			
			/*for(int j=i;j>=1;j--)
			{
				sum+=a[j];
				if(sum>M)break;
				tem=max(tem,a[j]);
				dp[i]=min(dp[i],dp[j-1]+tem);
			}*/
		}
		if(dp[n]==INF)printf("-1\n");
		else cout<<dp[n]<<endl;
		
	}
	return 0;
}




